	var c=0, t=null, stepNo=0, testNum=71;
	//开始计时
	function timerStart(){
		$('#timer').val(c);
		c=c+1;
		t=setTimeout("timerStart()",1400);
	}
	//停止计时
	function timerStop(){
		clearTimeout(t);
	}

	//开始答题
	$('.dkjohn-tip-start').click(function() {
		timerStart();
		$('.dkjohn-tip').addClass('hidden');
		$('.dkjohn-test-stage1').removeClass('hidden');
		$('.dkjohn-test1').removeClass('hidden');
	});
	
	//下一题
	$('.dkjohn-next').bind('click', function(){
		var selvalue = $("input[name='user-sel']").val();
		selvalue += $(this).val() + ',';
		$("input[name='user-sel']").val(selvalue);
		var curId = $(this).attr('id');
		var curPos =parseInt(curId.substr(0, curId.length-1));
		var nextPos = curPos + 1;
		$(this).parent().parent().find('input').attr('disabled', 'disabled');
		if(curPos == testNum) timerStop();
		if(curPos<=c){
			stepNo=stepNo+1;
			perc = parseInt(stepNo/testNum*100);
			perc = perc >= 100 ? 100 : perc;
			$('.progress-bar').css('width', perc+'%');
			$('.dkjohn-percent').data('percent', perc);
			$('.dkjohn-percent').html(perc+'%');
			$('.dkjohn-percent').css('position','relative');

			setTimeout(function() {
				$('.dkjohn-test'+curPos).fadeOut(function() {
						if(curPos<=testNum){
							$('.dkjohn-test'+nextPos).removeClass('hidden');
						}
						if(perc == 100) {
							if(selvalue.substr(selvalue.length-1, 1) == ',')
								$("input[name='user-sel']").val(selvalue.substr(0, selvalue.lastIndexOf(',')));
							$('.progress').addClass('hidden');
							if(sf != 'sf')
								$('.user-info-form').removeClass('hidden');
							else
								$('.sfuser-next-form').removeClass('hidden');
						}
					}
				);
			},500);
		} else {
			
			 $('.dkjohn-test'+curPos).html('<blockquote style="border-color:#96E756;"><p>亲，您点得太快了，一定要认真测试才准哦！</p><p><button type="button" class="btn btn-primary btn-sm dkjohn-btn-retest">重新开始</button></p></blockquote>');
		}
	});

	//重新做题
	$('.dkjohn-btn-retest').live('click', function() {
		window.location.reload();
	});
	
	$('#form-stage1').ajaxForm({
		url: basepath + '/contoller/save.do',
		type: 'POST',
		beforeSubmit: function(arr) {
			if(sf != 'sf') {
				if(checkName($('#username')) == false) return false;
				if(checkPhone($('#usertel')) == false) return false;
				if($.trim($('#code').val()).length == 0) {
					errorMsg($('.user-info-form'), '请输入验证码。', 'form-group');
					$('.alert').addClass('col-sm-5 col-sm-offset-3');
					return false;
				}
				var returnflag = false;
				
				$.ajax({
					async: false,
		            type: "POST",
		            url: "../../sms/smsverific.action",
		            data: {username:$.trim($("#username").val()), usertel:$.trim($("#usertel").val()),vsmscode:$.trim($('#code').val())},
		            success: function(data){
		            	var res =  eval(data)[0];
		            	if(res.smsverific == 'true') {
		            		returnflag = true;
		            	}
		            },
		            error:function(data){
		            	
		            }
		        });
				if(!returnflag){
					$('button[type="submit"]').button('reset');
					errorMsg($('.user-info-form'), '验证码不正确。', 'form-group');
					$('.alert').addClass('col-sm-5 col-sm-offset-3');
				}else{
					$('button[type="submit"]').button('loading');
				}
				return returnflag;
			}
			$('button[type="submit"]').button('loading');
			return true;
		},
		success: function(data, status) {
			//判断验证码
			if(sf != 'sf') {
				if(data){
					window.location.href = basepath + data;
					//'/jsp/result/reprt_1.jsp';
				}
			} else {//返回“next”
				
				window.location.href = 'stage_2.jsp';
			}
			
		},
		error: function(xhr, status) {
			$('button[type="submit"]').button('reset');
			errorMsg($('#form-stage1'), '网络错误。('+status+')', 'form-group');
			$('.alert').addClass('col-sm-6 col-sm-offset-3');
	    }
	});

